<?php
/**
 * Created by PhpStorm.
 * User: Hong
 * Date: 2018/3/24
 * Time: 15:33
 * Function:
 */

namespace Admin\Controllers\BaseInfo;

use Admin\Controllers\BaseAdminController;
use Admin\Resources\DepartmentResources;
use Illuminate\Http\Request;
use Platform\Models\Admin\AboutUs;
use Platform\Models\Admin\Permission;
use Platform\Models\Admin\Department;
use Platform\Repository\Admin\DepartmentRepository;
use Platform\System\Tools\ResultTool;

/**
 * @module 关于我们
 * Class RoleController
 * @package App\Http\Controllers\Admin\System
 */
class AboutController extends BaseAdminController
{

    protected $about;

    public function __construct()
    {
        parent::__construct();
        $about = AboutUs::first();
        if (!$about) $about = AboutUs::create(['content' => '']);
        $this->about = $about;
    }

    /**
     * @permission 查看
     *
     * @return \Illuminate\Http\JsonResponse
     * @throws \Exception
     */
    public function show(){

        return myResult()->setData($this->about)->send();
    }

    /**
     * @permission 编辑
     *
     * @param Request $request
     * @return \Illuminate\Http\RedirectResponse
     */
    public function store(Request $request)
    {
        $this->about->content = $request->get('content','');
        $this->about->save();

        return myResult()->setCode(ResultTool::CODE_SUCCESS,'编辑成功')->send();
    }

}